import axios from "axios";
import BaseUrl from './url.js'
export default function http(methods, url, data) {
  url = BaseUrl + url;
  console.log(url)
  var p = new Promise((reslove, reject) => {
    if (methods == 'get') {
      axios.get(url).then((res) => {
        reslove(res)
      }).catch(error => {
        reject(error)
      })
    }
    if (methods == 'post') {
      axios.post(url, data).then((res) => {
        reslove(res)
      }).catch(error => {
        reject(error)
      })
    }

  })
  return p
}
axios.interceptors.request.use(function (config) {
  const token=sessionStorage.token
  if(token){
      config.headers['token'] = token
  }

  config.withCredentials = true
  return config
}, function (error) {
  return Promise.reject(error)
})
